#ifndef CANVAS_H
#define CANVAS_H

#include <QWidget>
#include <QMouseEvent>
#include <QWheelEvent>
#include <QResizeEvent>
#include <QTimer>
#include "terraria/terrabrush.h"

class Canvas : public QWidget
{
    Q_OBJECT
public:
    explicit Canvas(QWidget *parent = nullptr);
    virtual ~Canvas();

protected:
    // 鼠标按下
    virtual void mousePressEvent(QMouseEvent* event) override;

    // 鼠标抬起
    virtual void mouseReleaseEvent(QMouseEvent* event) override;

    // 鼠标移动
    virtual void mouseMoveEvent(QMouseEvent* event) override;

    // 鼠标滚轮滚动
    virtual void wheelEvent(QWheelEvent* event) override;

    // 窗口尺寸变化
    virtual void resizeEvent(QResizeEvent* event) override;

    // 绘图
    virtual void paintEvent(QPaintEvent *event) override;

private:
    // 界面刷新时钟
    QTimer* update_timer = nullptr;

    // 界面刷新间隔(ms)
    int update_interval = 20;

    // 读取配置
    void readConfig();

    // 写入配置
    void saveConfig();

    TerraBrush brush;

signals:
};

#endif // CANVAS_H
